package com.kgc.activityprovider.controller;

import com.kgc.activiti.pojo.WorkFlow;
import com.kgc.activiti.remote.WorkFlowRemote;
import com.kgc.activiti.util.ResponseMsg;
import com.kgc.activityprovider.listener.MyExecutionListener;
import com.kgc.activityprovider.listener.MyTaskListener;
import com.kgc.activityprovider.service.WorkFlowService;
import org.activiti.engine.delegate.event.ActivitiEventType;
import org.activiti.engine.runtime.ProcessInstance;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
public class WorkFlowController implements WorkFlowRemote {

    private Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    private WorkFlowService workFlowService;

    @Override
    public ResponseMsg exportWorkFlow(WorkFlow workFlow, String xml){
        ResponseMsg msg = workFlowService.exportWorkerFlow(workFlow, xml);
        return msg;
    }

    @Override
    public ResponseMsg getWorkFlowList(Map<String, Object> paramMap) {
        logger.info("WorkFlowController getWorkFlowList paramMap:"+paramMap);
        ResponseMsg msg = workFlowService.getWorkFlowList(paramMap);
        logger.debug("WorkFlowController getWorkFlowList msg:"+msg);
        return msg;
    }

    @Override
    public ResponseMsg showWorkFlow(String url) {
        logger.info("WorkFlowController showWorkFlow url:"+url);
        ResponseMsg msg = workFlowService.showWorkFlow(url);
        logger.debug("WorkFlowController showWorkFlow msg:"+msg);
        return msg;
    }

    @Override
    public ResponseMsg editWorkFlow(WorkFlow workFlow, String xml){
        logger.info("WorkFlowController EditWorkFlow workFlow:"+workFlow+"xml:"+xml);
        ResponseMsg msg = workFlowService.editWorkFlow(workFlow, xml);
        logger.debug("WorkFlowController EditWorkFlow msg:"+msg);
        return msg;
    }

    //String code, Integer type
    @Override
    public ResponseMsg startProcess(Map<String,Object> params) {
        logger.info("WorkFlowController startProcess params:"+params);
        ResponseMsg msg = workFlowService.startProcess(params);
        logger.debug("WorkFlowController startProcess msg:"+msg);
        return msg;
    }

    @Override
    public ResponseMsg selectWorkFlowByType(Integer type) {
        logger.info("WorkFlowController selectWorkFlowByType type:"+type);
        ResponseMsg msg = workFlowService.selectWorkFlowByType(type);
        logger.debug("WorkFlowController selectWorkFlowByType msg:"+msg);
        return msg;
    }

    @Override
    public ResponseMsg competeTask(Map<String,Object> param) {
        logger.info("WorkFlowController competeTask param:"+param);
        ResponseMsg msg = workFlowService.competeTask(param);
        logger.debug("WorkFlowController competeTask msg:"+msg);
        return msg;
    }

    @Override
    public ResponseMsg checkCodeExit(String code) {
        logger.info("WorkFlowController checkCodeExit code:"+code);
        ResponseMsg msg = workFlowService.checkCodeExit(code);
        logger.debug("WorkFlowController checkCodeExit msg:"+msg);
        return msg;
    }

    @Override
    public ResponseMsg checkTypeExit(Integer type) {
        logger.info("WorkFlowController checkTypeExit type:"+type);
        ResponseMsg msg = workFlowService.checkTypeExit(type);
        logger.debug("WorkFlowController checkTypeExit msg:"+msg);
        return msg;
    }

    @Override
    public ResponseMsg checkNameExit(String name) {
        logger.info("WorkFlowController checkNameExit name:"+name);
        ResponseMsg msg = workFlowService.checkNameExit(name);
        logger.debug("WorkFlowController checkNameExit msg:"+msg);
        return msg;
    }

    @Override
    public ResponseMsg deployWorkFlow(String url) {
        logger.info("WorkFlowController deployWorkFlow type:"+url);
        ResponseMsg msg = workFlowService.deployWorkFlow(url);
        logger.debug("WorkFlowController deployWorkFlow msg:"+msg);
        return msg;
    }

    @Override
    public ResponseMsg reSubmit(Map<String, Object> params) {
        logger.info("WorkFlowController reSubmit params:"+params);
        ResponseMsg msg = workFlowService.startProcess(params);
        logger.debug("WorkFlowController reSubmit msg:"+msg);
        return msg;
    }
}
